home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Support / BCHashTa.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  1.9 KB  |  73 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  BCHashTa.h
  5. //
  6. //  This file contains the declaration of the open hash table class.
  7.  
  8. #ifndef BCHASHTA_H
  9. #define BCHASHTA_H 1
  10.  
  11. #include "BCType.h"
  12. #include "BCExcept.h"
  13. #include "BCNodes.h"
  14.  
  15. // Class denoting an open hash table
  16.  
  17. template<class Item, class Value, BC_Index Buckets, class Container>
  18. class BC_TTable {
  19. public:
  20.  
  21.   BC_TTable()
  22.     : fValidCache(0),
  23.       fSize(0),
  24.       fHash(0) {}
  25.   BC_TTable(BC_Index (*hash)(const Item&))
  26.     : fValidCache(0),
  27.       fSize(0),
  28.       fHash(hash) {}
  29.   BC_TTable(const BC_TTable<Item, Value, Buckets, Container>&);
  30.   ~BC_TTable()
  31.     {Clear();}
  32.  
  33.   BC_TTable<Item, Value, Buckets, Container>& operator=
  34.     (const BC_TTable<Item, Value, Buckets, Container>&);
  35.   BC_Boolean operator==
  36.     (const BC_TTable<Item, Value, Buckets, Container>&) const;
  37.   BC_Boolean operator!=
  38.     (const BC_TTable<Item, Value, Buckets, Container>& t) const
  39.       {return !operator==(t);}
  40.  
  41.   void SetHashFunction(BC_Index (*hash)(const Item&))
  42.     {BC_Assert((!fHash), BC_XDuplicate("BC_TTable<>::SetHashFunction", BC_kDuplicate));
  43.      fHash = hash;}
  44.   void Clear();
  45.   BC_Boolean Bind(const Item&, const Value&);
  46.   BC_Boolean Rebind(const Item&, const Value&);
  47.   BC_Boolean Unbind(const Item&);
  48.  
  49.   BC_Index Extent() const
  50.     {return fSize;}
  51.   BC_Boolean IsBound(const Item&) const;
  52.   const Value* ValueOf(const Item&) const;
  53.   const Container *const Bucket(BC_Index bucket) const
  54.     {BC_Assert((bucket < Buckets),
  55.                BC_XRangeError("BC_TTable<>::Bucket", BC_kInvalidIndex));
  56.      return &fRep[bucket];}
  57.   Container* Bucket(BC_Index bucket)
  58.     {BC_Assert((bucket < Buckets),
  59.                BC_XRangeError("BC_TTable<>::Bucket", BC_kInvalidIndex));
  60.      return &fRep[bucket];}
  61.  
  62. protected:
  63.  
  64.   Container fRep[Buckets];
  65.   BC_TPair<Item, Value> fCache;
  66.   BC_Boolean fValidCache;
  67.   BC_Index fSize;
  68.   BC_Index (*fHash)(const Item&);
  69.   
  70. };
  71.  
  72. #endif
  73.